<?php

use yii\helpers\Html;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('common', 'list');
$this->params['breadcrumbs'][] = $this->title;
?>
<style>
    .content-wrapper .content {
        padding-top: 0px!important;
    }
</style>
<?=Html::cssFile('/static/plugins/jstree/dist/themes/default/style.min.css')?>
<?=Html::jsFile('/static/plugins/jstree/dist/jstree.min.js')?>
<div class="article-category-index">
    <div class="col-lg-12">
        <div class="col-lg-3">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div id="jstree_tree"></div>
                </div>
            </div>
        </div>
        <div class="col-lg-9">
            <div class="panel">
                <div class="panel-body" id="content-body">
                    <div id="list"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="formModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">Modal title</h4>
            </div>
            <div class="modal-body modal-body-view"></div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
    var tree = '<?=Yii::$app->urlManager->createUrl([Yii::$app->controller->id.'/tree'])?>';
    var list = '<?=Yii::$app->urlManager->createUrl([Yii::$app->controller->id.'/list'])?>';
    $(function () {
        loadTree();
        loadList(0);
    });

    function loadTree() {
        $.get(tree, function (r) {
            if (r){
                $("#jstree_tree").html(r);
            }else{
                alert('网络错误.');
                return false;
            }
        })
    }

    function reloadtree() {
        saveRefeshLeftTree('jstree');
    }

    //保存和刷新左边的树
    function saveRefeshLeftTree(tree){
        $.jstree.reference('#'+tree).save_state();
        $.jstree.reference('#'+tree).refresh();
    }

    function loadList(treeNodeId) {
        //loadTree();
        $.get(list, {treeNodeId: treeNodeId}, function (r) {
            if (r){
                $("#list").html(r);
                reloadtree();
            }else{
                alert('网络错误.');
                return false;
            }
        })
    }

    function reloadForm(treeNodeKid) {
        //loadTree();
        $.get(list, {treeNodeId: treeNodeKid}, function (r) {
            if (r){
                $("#list").html(r);
            }else{
                alert('网络错误.');
                return false;
            }
        })
    }
</script>